package com.lezijie.note.service;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.Digester;
import com.lezijie.note.dao.UserDao;
import com.lezijie.note.po.User;
import com.lezijie.note.vo.ResultInfo;

public class UserService {
    UserDao userDao=new UserDao();
    public ResultInfo<User> UserLogin(String name,String pwd){
        ResultInfo resultInfo=new ResultInfo();
        if(name==null){
            resultInfo.setCode(0);
            resultInfo.setMsg("用户名不能为空");
            return  resultInfo;
        }
        if(pwd==null){
            resultInfo.setCode(0);
            resultInfo.setMsg("密码不能为空");
            return  resultInfo;
        }
        User user= userDao.queryUser(name);
        if(user==null){
            resultInfo.setCode(0);
            resultInfo.setMsg("用户名不存在");
            return  resultInfo;
        }
        String s = DigestUtil.md5Hex(pwd);
        System.out.println(s);
        if(!s.equals(user.getUpwd())){
            resultInfo.setCode(0);
            resultInfo.setMsg("密码错误");
            return  resultInfo;
        }
        resultInfo.setCode(1);
        resultInfo.setResult(user);
        return  resultInfo;
    }
}
